package com.artqiyi.dollmachine.presenter;

import com.artqiyi.dollmachine.common.constant.ServerConstant;
import com.artqiyi.dollmachine.presenter.base.BasePresenter;
import com.artqiyi.dollmachine.presenter.base.PresenterCallbackCollection;
import com.artqiyi.dollmachine.utils.Callback.MyStringCallback;
import com.artqiyi.dollmachine.utils.JSONUtils;
import com.artqiyi.dollmachine.utils.manager.HttpManager;
import com.artqiyi.dollmachine.utils.respone.BannerRespone;
import com.artqiyi.dollmachine.utils.respone.ConfigRespone;
import com.artqiyi.dollmachine.utils.respone.DollListRespone;
import com.artqiyi.dollmachine.utils.respone.TipRespone;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import timber.log.Timber;

/**
 * Created by Administrator on 2017/10/26 0026.
 */

public class DollPresenter extends BasePresenter {

    public void getBanner() {
        HttpManager.getHttpRequest(ServerConstant.getBanner(), null, new MyStringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                ((PresenterCallbackCollection.DollFragmentCallBack) mCallback).onGetBannerFail("请求轮播图失败");
            }

            @Override
            public void onResponse(String response, int id) {
                BannerRespone bannerRespone = JSONUtils.jsonString2Bean(response, BannerRespone.class);
                ((PresenterCallbackCollection.DollFragmentCallBack) mCallback).onGetBannerSuccess(bannerRespone.getData());
            }
        });
    }

    //首页娃娃抓中列表
    public void getTipList() {
        HttpManager.getHttpRequest(ServerConstant.getHomeCatchList(), null, new MyStringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                Timber.d("Tip_Error:" + e.toString());
                ((PresenterCallbackCollection.DollFragmentCallBack) mCallback).onTipListFail(e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                Timber.d("Tip_response:" + response);
                TipRespone tipRespone = JSONUtils.jsonString2Bean(response, TipRespone.class);
                ((PresenterCallbackCollection.DollFragmentCallBack) mCallback).onTipListSuccess(tipRespone.getData());
            }
        });
    }

    public void getDollList(int pageNum) {
        Map<String, String> params = new HashMap<>();
        params.put("page", String.valueOf(pageNum));
        params.put("per_page", "20");
        HttpManager.getHttpRequest(ServerConstant.getDollList(), params, new MyStringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                ((PresenterCallbackCollection.DollFragmentCallBack) mCallback).onGetDollListFail(e.getMessage());
            }

            @Override
            public void onResponse(String response, int id) {
                Timber.d("getDollList_response:" + response);
                DollListRespone dollListRespone = JSONUtils.jsonString2Bean(response, DollListRespone.class);
                ((PresenterCallbackCollection.DollFragmentCallBack) mCallback).onGetDollListSuccess(dollListRespone.getData());
            }
        });
    }

}
